home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 15758 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.7 KB  |  69 lines

  1. Path: baygate.bayarea.net!usenet
  2. From: Amir@bayarea.net (Amir)
  3. Newsgroups: comp.lang.c++,comp.lang.c
  4. Subject: Re: HELP on abstraction!!!
  5. Date: Sun, 07 Apr 1996 00:04:08 GMT
  6. Organization: Bay Area Internet Solutions (408)447-8690
  7. Message-ID: <316704f9.4805163@news>
  8. References: <4jok9c$a6e@merkurius.lu.se>
  9. NNTP-Posting-Host: amir.bayarea.net
  10. X-Newsreader: Forte Agent .99d/32.168
  11.  
  12. On 1 Apr 1996 13:04:44 GMT, magnus_dahlberg@hermes.ics.lu.se (Magnus
  13. Dahlberg) wrote:
  14.  
  15. >Hello everyone!
  16. >
  17. >I'm writing a C++ programme that should be able to use both arrays and
  18. >linked lists without changing the functions. Is it possible, for
  19. >example, to insert a new person in my list (queue) without knowing if
  20. >it's an array or a linked list? And if it is, how do I do it? 
  21. >
  22. >Please, I need help quickly!
  23. >Send your answers to: magnus_dahlberg@hermes.ics.lu.se
  24. >
  25. >Thanx!
  26. >
  27. >
  28.  
  29. Sure, all you need to have a common base class to the array and the
  30. link list, and than just have the method as a virtual like: 
  31.  
  32. class Common {
  33. ...
  34. public:
  35. virtual Error AddMember(Person & P) = 0;
  36. ...
  37. };
  38.  
  39. class MyArray : public Common {
  40. ...
  41. public:
  42. virtual Error AddMember(Person & P);
  43. ...
  44. };
  45.  
  46.  
  47. class MyList public Common {
  48. ...
  49. public:
  50. virtual Error AddMember(Person & P);
  51. ...
  52. };
  53.  
  54. ...
  55.  
  56.  
  57. Amir
  58.  
  59.                     \\||||//
  60.                     \ o  o /
  61. ______________.ooO__(  ()  )__Ooo._______________________________
  62.  
  63.    Amir Deutel                  http://www.bayarea.net/~amir/
  64.                                 
  65.                  .oo0O   O0oo.  Work: Amir.D@AppleLink.Apple.com
  66.                  (   )   (   )  Home: Amir@bayarea.net 
  67. __________________\ (_____) /____________________________________
  68.                    \_)   (_/
  69.